"""
1递归介绍
2 递归与栈的关系
3递归的作用
4 递归的总结
1）必须有一个明确的结束条件，要不就会变成死循环，最终撑爆系统
2）每次进入更深一层递归时，问题规模相比上次递归都应有所减少
3）递归执行效率不高，递归层次过多会导致栈溢出


递归的应用－－－－阶乘

"""

<<<<<<< HEAD
# def factorial(n):
#     if n == 1:
#         return 1
#     return n * factorial(n-1)
#
# data = factorial(5)
# print(data)
=======
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)

data = factorial(5)
print(data)
>>>>>>> dev

"""
尾递归优化

"""
<<<<<<< HEAD
#
# def digui(n):
#     print(n)
#     digui(n+1)
#
# digui(1)


# def calc(n):
#     v =int(n/2)
#     print(v)
#     if v == 0:
#         return "finsh"
#     calc(v)
#     print(v)
#
# calc(10)


# 阶乘
# def fact(n):
#     if n ==1:
#         return 1
#     return n*fact(n-1)
#
# data = fact(5)
# print(data)

#尾递归

def cal(n):
    print(n)
    return cal(n+1)

cal(1)
=======



>>>>>>> dev
